Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide local testing functionality #172

Merged
merged 9 commits into from
Apr 24, 2024
Merged

Provide local testing functionality #172

merged 9 commits into from
Apr 24, 2024

Conversation

JR-1991
Copy link
Member

@JR-1991 JR-1991 commented Dec 28, 2023

Changes this PR introduces

  • Adds local testing functionality using Docker
  • Users can run tests via the run-tests.sh script
  • Python versions can be specified via the -p flag

Why this change is required

  • Local tests require a working Dataverse instance
  • GitHub testing workflow should be reflected

image

ToDos

  • Add a description on how to run single tests
    • How to retrieve the API_TOKEN and SERVER_URL without the provided script

How to run the tests

In order to run the tests, you need to have a Dataverse instance running. We have prepared a shell script that will start a Dataverse instance using Docker that runs all tests in a clean environment. To run the tests, execute the following command:

# Defaults to Python 3.11
./run_tests.sh

# To run the tests with a specific Python version
./run_tests.sh -p 3.8

Once finished, you can find the test results in the dv/unit-tests.log file and in the terminal.

Manual setup

If you want to run single tests you need to manually set up the environment and set up the necessary environment variables. Please follow the instructions below.

1. Start the Dataverse instance

docker compose \
    -f ./docker/docker-compose-base.yml \
    --env-file local-test.env \
    up -d

2. Set up the environment variables

export BASE_URL=http://localhost:8080
export DV_VERSION=6.2 # or any other version
export $(grep "API_TOKEN" "dv/bootstrap.exposed.env")
export API_TOKEN_SUPERUSER=$API_TOKEN

3. Run the test(s) with pytest

python -m pytest -v

Closes #169

- Spins up a Dataverse installation similar to the test action
- Allows to specify the version of Python to test against
@JR-1991 JR-1991 self-assigned this Dec 28, 2023
@JR-1991 JR-1991 added type:feature New feature pkg:testing test related activities prio:asap Fix as soon as possible status:for review Waiting to be reviewd labels Dec 28, 2023
@JR-1991 JR-1991 requested a review from pdurbin December 28, 2023 21:31
@poikilotherm
Copy link
Member

A note here: wouldn't it make sense to require folks to run the integration tests using pytest on their machine (potentially using poetry) and use sth like Testcontainers for Python to run a Compose config?

It's the same thing as within the upstream codebase: using Testcontainers lets you regain control over service dependencies from within testing and not rely on outside control scripts.

@JR-1991
Copy link
Member Author

JR-1991 commented Dec 29, 2023

I agree, running Dataverse and tests independently would be great! I've gone with this solution mainly due to retrieving the API Token and ingesting it into the testing workflow. It replicates what the Dataverse action does and leaves the "technicalities" to the bash script.

My main concern with going for an independent solution would be that users still need a way to extract the API Token into their environment for tests to run successfully. Effectively, this would always require some intermediate script since I am not able to hardcode this into tests.

Thanks for the repo! Maybe re-structuring the tests around Testcontainers and parsing the logs could work. I will check the repo out tomorrow - Enough "Nachtschicht" for today 😁

@pdurbin
Copy link
Member

pdurbin commented Jan 5, 2024

Hey @kuriwaki and @wibeasley you might want something like this for https://github.com/IQSS/dataverse-client-r

@JR-1991 JR-1991 marked this pull request as draft January 31, 2024 12:14
@pdurbin pdurbin added this to the 0.3.2 milestone Mar 4, 2024
@JR-1991
Copy link
Member Author

JR-1991 commented Apr 11, 2024

@poikilotherm @pdurbin, I just wanted to give you a quick update. I've been working on the README.md file and added new instructions to make things easier for everyone. I have added instructions on how to run all tests at once in a shell script, as was initially proposed in this PR. The docs also include a recipe on how to set up everything manually if one wants to run single tests.

Can you test or review the recent additions?

@JR-1991 JR-1991 marked this pull request as ready for review April 11, 2024 22:17
@JR-1991 JR-1991 merged commit 4511df2 into master Apr 24, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:testing test related activities prio:asap Fix as soon as possible status:for review Waiting to be reviewd type:feature New feature
Projects
Development

Successfully merging this pull request may close these issues.

Local testing of pyDataverse
3 participants